home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE19 / EX6.C < prev    next >
C/C++ Source or Header  |  1995-05-14  |  3KB  |  60 lines

  1. #include <windows.h>
  2. #include <winreg.h>
  3.  
  4. #include <genstub.c>
  5.  
  6. LRESULT FAR PASCAL WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  7. {
  8.     switch ( uMsg )
  9.     {
  10.         case WM_COMMAND:
  11.             switch ( wParam )
  12.             {
  13.                 case IDM_TEST:
  14.                 {                              // Test option.
  15.                     LONG lRes1, lRes2;         // Holds results of key finds.
  16.                     char szBuffer[256];        // Buffer to store the values.
  17.                     HKEY hKeyIcons;            // RTF default icon key.
  18.                     HKEY hKeyFileType;         // RTF file key.
  19.  
  20.                     // Open a key for rtffile.
  21.                     lRes1 = RegOpenKeyEx( HKEY_CLASSES_ROOT, // registry root
  22.                                           "rtffile\\DefaultIcon", // icon name
  23.                                           0, KEY_ALL_ACCESS, &hKeyIcons );
  24.                     lRes2 = RegOpenKeyEx( HKEY_CLASSES_ROOT, // registry root
  25.                                           "rtffile", 0, KEY_ALL_ACCESS,
  26.                                           &hKeyFileType );
  27.                     if ( ( lRes1==ERROR_SUCCESS ) && ( lRes2==ERROR_SUCCESS ) )
  28.                     {
  29.                         DWORD dwType;
  30.                         LPTSTR lpszBuffer;
  31.                         DWORD dwBytes = 128;
  32.                         RegQueryValueEx( hKeyFileType, "", 0, &dwType,
  33.                                          szBuffer, &dwBytes );
  34.                         // Make message.
  35.                         lpszBuffer = &szBuffer[lstrlen( szBuffer )];
  36.                         lstrcat( lpszBuffer, " icons are found in file " );
  37.                         lpszBuffer = &szBuffer[lstrlen( szBuffer )];
  38.                         dwBytes = 128;
  39.                         RegQueryValueEx( hKeyIcons, "", 0, &dwType,
  40.                                          lpszBuffer, &dwBytes );
  41.                     }
  42.                     else
  43.                         lstrcpy( szBuffer, "Rich Text File Information Not Found" );
  44.                     // Put message to screen.
  45.                     MessageBox( hWnd, szBuffer, "Registry Query", MB_OK );
  46.                 }
  47.                 break;
  48.                 case IDM_EXIT:
  49.                     DestroyWindow( hWnd );
  50.                     break;
  51.             }
  52.         break;
  53.         case WM_DESTROY:
  54.             PostQuitMessage( 0 );
  55.         break;
  56.         default:            // default windows message processing
  57.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  58.     }
  59.     return( 0L );
  60. }